
package com.snail.mobile.sim.oss.videoinfo.dao.hibernate;

import java.util.Collection;
import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.criterion.Example;
import org.hibernate.criterion.MatchMode;
import org.hibernate.criterion.Order;
import org.springframework.orm.ObjectRetrievalFailureException;
import org.springframework.orm.hibernate3.HibernateCallback;

import com.sungrid.seine.oss.framework.dao.hibernate.BaseDaoHibernate;
import com.snail.mobile.sim.oss.videoinfo.model.TblVideoInfoOss;
import com.snail.mobile.sim.oss.videoinfo.dao.TblVideoInfoOssDao;

public class TblVideoInfoOssDaoHibernate extends BaseDaoHibernate implements TblVideoInfoOssDao 
{
    /**
     * @see com.snail.mobile.sim.oss.videoinfo.dao.TblVideoInfoOssDao#getTblVideoInfoOss(Integer nid)
     */
    public TblVideoInfoOss getTblVideoInfoOss(final Integer nid) 
    {
        TblVideoInfoOss tblVideoInfoOss = (TblVideoInfoOss) getHibernateTemplate().get(TblVideoInfoOss.class, nid);
        if (tblVideoInfoOss == null) 
        {
            log.warn("uh oh, tblVideoInfoOss with nid '" + nid + "' not found...");
            throw new ObjectRetrievalFailureException(TblVideoInfoOss.class, nid);
        }

        return tblVideoInfoOss;
    }

    /**
     * @see com.snail.mobile.sim.oss.videoinfo.dao.TblVideoInfoOssDao#saveTblVideoInfoOss(TblVideoInfoOss tblVideoInfoOss)
     */    
    public void saveTblVideoInfoOss(final TblVideoInfoOss tblVideoInfoOss) 
    {
        getHibernateTemplate().save(tblVideoInfoOss);
    }

    /**
     * @see com.snail.mobile.sim.oss.videoinfo.dao.TblVideoInfoOssDao#saveOrUpdateTblVideoInfoOss(TblVideoInfoOss tblVideoInfoOss)
     */    
    public void saveOrUpdateTblVideoInfoOss(final TblVideoInfoOss tblVideoInfoOss) 
    {
        getHibernateTemplate().saveOrUpdate(tblVideoInfoOss);
    }

    /**
     * @see com.snail.mobile.sim.oss.videoinfo.dao.TblVideoInfoOssDao#removeTblVideoInfoOss(Integer nid)
     */
    public void removeTblVideoInfoOss(final Integer nid) 
    {
        getHibernateTemplate().delete(getTblVideoInfoOss(nid));
    }

    /**
     * @see com.snail.mobile.sim.oss.videoinfo.dao.TblVideoInfoOssDao#getTblVideoInfoOsss(com.snail.mobile.sim.oss.videoinfo.model.TblVideoInfoOss)
     */
    public List getTblVideoInfoOsss(final TblVideoInfoOss tblVideoInfoOss) 
    {
       //  return getHibernateTemplate().find("from TblVideoInfoOss order by nid desc");

        if (tblVideoInfoOss == null) 
        {
            return getHibernateTemplate().find("from TblVideoInfoOss");
        } else 
        {
            // filter on properties set in the tblVideoInfoOss
            HibernateCallback callback = new HibernateCallback() 
            {
                public Object doInHibernate(Session session) throws HibernateException 
                {
                    Example ex = Example.create(tblVideoInfoOss).ignoreCase().enableLike(MatchMode.ANYWHERE);
                    return session.createCriteria(TblVideoInfoOss.class).add(ex).addOrder(Order.desc("nid")).list();
                }
            };
            return (List) getHibernateTemplate().execute(callback);
        }
    }

    /**
     * @see com.snail.mobile.sim.oss.videoinfo.dao.TblVideoInfoOssDao#removeTblVideoInfoOsss(Collection tblVideoInfoOsss)
     */
    public void removeTblVideoInfoOsss(final Collection tblVideoInfoOsss)
    {
        getHibernateTemplate().deleteAll(tblVideoInfoOsss);
    }

    /**
     * @see com.snail.mobile.sim.oss.videoinfo.dao.TblVideoInfoOssDao#saveTblVideoInfoOsss(Collection tblVideoInfoOsss)
     */
    public void saveTblVideoInfoOsss(final Collection tblVideoInfoOsss)
    {
        getHibernateTemplate().saveOrUpdateAll(tblVideoInfoOsss);
    }
}
